<?php
namespace App\Logic\MonthlyReportLT;

use App\Models\MonthlyReportLT\Tmp\TmpCancel;
use App\Models\MonthlyReportLT\Tmp\TmpSales;

class MatchCancel
{
    public static function exe()
    {
        TmpCancel::query()
            ->orderBy('id')
            ->chunk(500, function ($items){
                foreach ($items as $item){
                    $query = TmpSales::query()
                        ->where('order_id', $item->order_id);
                    if($item->sku){
                        $query->where('sku', $item->sku);
                    }
                    $result = $query->get();
                    foreach ($result as $sale){
                        $sale->cancel_status = 1;
                        $sale->save();
                    }
                }
            });
    }
}
